package com.lagou;

import com.lagou.entity.User;
import com.lagou.mapper.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class controller {
    @Autowired
    private UserRepository userRepository;

    @RequestMapping("add")
    public String add(@RequestParam("name") String name){
        User user = new User();
        user.setName(name);
        userRepository.save(user);
        return "success";
    }
    @RequestMapping("list")

    public List<User> list(){
        List<User> all = userRepository.findAll();
        return all;
    }

    @RequestMapping("edit")

    public String edit(Integer id,String name){
        User user = new User();
        user.setId(id);
        user.setName(name);
        userRepository.save(user);
        return "success";

    }

    @RequestMapping("delete")
    public String delete(Integer id){
        userRepository.deleteById(id);

        return "success";
    }

}
